package com.tan.websocket.event;

import com.alibaba.fastjson.JSON;
import com.tan.common.dto.chat.ChatInfoDTO;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Tan
 * @description 接收者
 * @date 2025/1/28
 */
@Slf4j
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ChatGroupMember implements ChatEventListener<ChatInfoDTO> {

    private Long userId;

    private Channel channel;


    @Override
    public void onMessageReceived(ChatInfoDTO chatInfo) {
        log.info("接收到消息：{}", chatInfo);
        String message = JSON.toJSONString(chatInfo);
        channel.writeAndFlush(new TextWebSocketFrame(message));
    }
}
